package md8800;

import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.Port;
import javax.sound.sampled.Mixer.Info;

public class Sound
{

	public float getSoundlevel()
	{
		float volume = 0;
		final Port lineOut;
		try
		{
			Info[] info = AudioSystem.getMixerInfo();

			System.out.println(info[0].toString());
			System.out.println(info[1].toString());
			System.out.println(info[2].toString());
			System.out.println(info[3].toString());

			
			if (AudioSystem.isLineSupported(Port.Info.SPEAKER))
			{
				lineOut = (Port) AudioSystem.getLine(Port.Info.SPEAKER);
				lineOut.open();
			}
			else
			{
				System.out.println("Unable to get Output Port");
				return 0;
			}

			final FloatControl controlIn = (FloatControl) lineOut
					.getControl(FloatControl.Type.VOLUME);

			volume = 100 * (controlIn.getValue() / controlIn.getMaximum());
			System.out.println("LINE_OUT : volume = " + volume);
		}
		catch (final Exception e)
		{
			System.out.println(e + " LINE_OUT");
		}
		return volume;
	}
}
